﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication3.Models
{
    public class BreukRepository
    {
        BreukDataContext db = new BreukDataContext();

        public IQueryable<Breuk> GetBreuken()
        {
            var breuken = from b in db.Breuks
                          select b;
            return breuken;

        }


        public void AddBreuk(int teller, int noemer)
        {
            Breuk b = new Breuk();
            b.Teller = teller;
            b.Noemer = noemer;
            db.Breuks.InsertOnSubmit(b);
            db.SubmitChanges();
        }

        public Breuk GetBreuk(long id)
        {
            var breuk = (from b in db.Breuks
                         where b.Id == id
                         select b).Single();
            return breuk;
        }

        public void EditBreuk(Breuk breuk)
        {
            var br = GetBreuk(breuk.Id);
            br.Teller = breuk.Teller;
            br.Noemer = breuk.Noemer;
            db.SubmitChanges();
        }

        public void DeleteBreuk(long id)
        {
            var br = GetBreuk(id);
            db.Breuks.DeleteOnSubmit(br);
            db.SubmitChanges();
        }
    }
}
